﻿
    function openpopup(id) {
        //Calculate Page width and height
        var pageWidth = window.innerWidth;
        var pageHeight = window.innerHeight;
        if (typeof pageWidth != "number") {
            if (document.compatMode == "CSS1Compat") {
                pageWidth = document.documentElement.clientWidth;
                pageHeight = document.documentElement.clientHeight;
            } else {
                pageWidth = document.body.clientWidth;
                pageHeight = document.body.clientHeight;
            }
        }
        //Make the background div tag visible...
        var divbg = document.getElementById('bg');
        divbg.style.visibility = "visible";

        var divobj = document.getElementById(id);
        divobj.style.visibility = "visible";
        if (navigator.appName == "Microsoft Internet Explorer")
            computedStyle = divobj.currentStyle;
        else computedStyle = document.defaultView.getComputedStyle(divobj, null);
        //Get Div width and height from StyleSheet
//        var divWidth = computedStyle.width.replace('px', '');
//        var divHeight = computedStyle.height.replace('px', '');
//        var divLeft = (pageWidth - divWidth) / 2;
//        var divTop = (pageHeight - divHeight) / 2;
//        //Set Left and top coordinates for the div tag
//        divobj.style.left = divLeft + "px";
//        divobj.style.top = divTop + "px";
        //Put a Close button for closing the popped up Div tag
        if (divobj.innerHTML.indexOf("closepopup('" + id + "')") < 0)
            divobj.innerHTML = "<a href=\"#\" onclick=\"closepopup('" + id + "')\"><span class=\"close_button\">X</span></a>" + divobj.innerHTML;
        if (divobj.innerHTML.indexOf("sendemail()") < 0) {
            divobj.innerHTML = "&nbsp;<a href=\"#\" onclick=\"sendemail();\"><img src=\"images/email.jpg\"></a>" + divobj.innerHTML;
            divobj.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;<input name=\"emailaddress\" id=\"emailaddress\" type=\"text\" placeholder=\"Your email address\"/>" + divobj.innerHTML;
            
        }
        if (divobj.innerHTML.indexOf("printpage('" + id + "')") < 0)
            divobj.innerHTML = "<a href=\"#\" onclick=\"printpage('" + id + "');\"><img src=\"Styles/Print/images/icon-print.png\"></a>" + divobj.innerHTML;

    }

    function sendemail() {
        var address = document.getElementById('emailaddress').value;
        //alert(address);
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(address)) {
            alert('Please provide a valid email address');
            email.focus;
            return false;
        }

        var recipeid = document.getElementById('inputRecipeId').value;
//        alert(recipeid);
        var ListIngredientName = document.getElementById('inputIngredientEmail').value;
        var page = 'SendEmail.aspx?emailaddress=' + address + "&IngredientName=" + ListIngredientName + "&recipeid=" + recipeid;

        self.location = page;
        
    }


//    function printpage() {
//        window.print();
//    }
    function printpage(printpage) {
        var headstr = "<html><head><title></title></head><body>";
        var footstr = "</body>";
        var newstr = document.all.item(printpage).innerHTML;
        var oldstr = document.body.innerHTML;
        document.body.innerHTML = headstr + newstr + footstr;
        window.print();
        document.body.innerHTML = oldstr;
        return false;
    }

    function closepopup(id) {
        var divbg = document.getElementById('bg');
        divbg.style.visibility = "hidden";
        var divobj = document.getElementById(id);
        divobj.style.visibility = "hidden";
    }